<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>商品列表</title>
<script type="text/javascript" src="../boot.js"></script>
<script>
var tbgrid;

function parsePage(){

$('#toolbar').toolbar({
	items: [{
				text : '添加商品',
				iconCls : 'icon-add',
				handler : function() {
					add();
				}
			}, '-', {
				text : '删除',
				iconCls:'icon-del',
				handler : function() {
					var node = tbgrid.datagrid('getSelections');
					var ids=[];
					$.each(node,function(index,val){
						ids.push(val.id);
					});
					del(ids);
				}
			},'-',{
				text : '商品信息更新',
				iconCls:'icon-reload',
				handler : function() {
					var node = tbgrid.datagrid('getSelections');
					var ids=[];
					$.each(node,function(index,val){
						ids.push(val.id);
					});
					refreshGoods(ids);
				}
			},'-',{
				text : '导入',
				iconCls:'icon-import',
				handler : function() {
					exportBrand();
				}
			},'-',{
				text : '导出',
				iconCls:'icon-export',
				handler : function() {
					exportBrand();
				}
			}] 
});


toolSearch({
	items:[{"text":"商品编码","name":"goodsno"},{"text":"商品简称","name":"goodsno"}],
	callback:function(key,name){
			if(key==""){
				showInfo('请输入关键字');
				return;
			}
		showInfo(key);
	}
});	



tbgrid = $('#tbList').datagrid({
			url: '../json/goods/goods.json?r='+Math.random(),
			singleSelect:true,
			fitColumns:true,
			frozenColumns : [[{
				title : 'id',
				field:'id',
				checkbox : true
			}]],
		    columns:[[
					{
					title:'商品编号',
					field:'col1',
					width:80,
					sortable:true
				    },
					{
					title:'商品名称',
					field:'col2',
					width:200,
					align:'left'
					},{
					title:'商品图片',
					field:'col3',
					width:100,
					formatter:function(value,rec,index){
						var str='<img src="'+value+'"  width="40" height="40" />';
						return str;
					}
					},{
					title:'属性分类',
					field:'col4',
					width:80
					},{
					title:'品牌',
					field:'col5',
					width:60
					},{
					title:'库存数量',
					field:'col6',
					width:60
					},{
					title:'结算价格',
					field:'col7',
					width:60,
					align:'right'
					},{
					title:'操作',
					field:'opt',
					width:100,
					formatter:function(value,rec,index){
						var str='<a href="javascript:;" class="jsEdit">编辑</a> | <a data-id='+rec.id+' href="javascript:;" class="jsDel">删除</a>';
						return str;
					}
					}
		]],
		onLoadSuccess:function(){
			//编辑
			$('.jsEdit').click(function(){
				var _this=$(this);
				return false;
			});
			
			//删除
			$('.jsDel').click(function(){
				var id=$(this).attr('data-id');
				del(id);
				return false;
			});
		
		}

	});

}


function del(id){
	if(id.length<=0){
		showError('请选择需要删除的项目！');
		return;
	}
	showConfirm('确认删除吗？',function(){					 
showSuc('删除成功！'+id);						$('#tbList').datagrid('reload');
				  
	});
}


function add(){
	top.addBlankTab({title:'添加货品',href:'goods/goods-add.html'});
}

//导出
function exportGoods(){
	
}



function refreshGoods(ids){
	if(ids.length<=0){
		showError('请选择需要更新的商品！');
		return;
	}
	top.addBlankTab({
		title:'更新商品信息',
		href:'goods/goods-update.html'
	});
}
</script>
</head>

<body class="easyui-layout">
<div data-options="region:'north',border:false" class="toolbar-region">
    <div id="toolbar">
    </div>
</div>
<div  data-options="region:'center',border:false">
		<!--subLayout start-->
    <div class="easyui-layout" data-options="fit:true" id="subLayout">
        <!--搜索start-->
        <div data-options="region:'north',border:false,closed:true" >
            <div class="search-div">
                <form name="searchForm" id="searchForm" action="" method="post" >
                    <table class="search-tb" >
                        <col width="80" />
                        <col/>
                        <col width="80" />
                        <col/>
                        <col width="80" />
                        <col/>
                        <tbody>
                            <tr>
                                <th>商品名称：</th>
                                <td><input class="ipt" /></td>
                                <th>商品品牌：</th>
                                <td><input class="ipt" /></td>
                                <th>上架时间：</th>
                                <td><input class="ipt easyui-datebox w80" /> <a class="easyui-linkbutton ml10" id="SearchBtn">搜索</a></td>
                                
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!--搜索end--> 
        <!--列表-->
        <div data-options="region:'center',border:false">
            <table id="tbList">
            </table>
        </div>
    </div>
    <!--subLayout end-->
</div>
</body>
</html>
